/**
 * @param {Number} num 数值
 * @returns {String} 处理后的字符串
 * @description 如果传入的数值小于10，即位数只有1位，则在前面补充0
 */
const getHandledValue = num => {
  return num < 10 ? '0' + num : num
}
/**
 * getFormartDate 获取格式化时间
 * date 时间戳
 * type :all 全格式 yyyy-MM-dd hh-mm-ss   year: yyyy-MM-dd
 */
export const getFormartDate = (tmpDate, type) => {
  //   let date1 = tmpDate.replace(' ', 'T')// 兼容IE
  const newDate = new Date(tmpDate)
  const year = newDate.getFullYear()
  const month = getHandledValue(newDate.getMonth() + 1)
  const date = getHandledValue(newDate.getDate())
  const hours = getHandledValue(newDate.getHours())
  const minutes = getHandledValue(newDate.getMinutes())
  const second = getHandledValue(newDate.getSeconds())
  let computedDate = ''
  if (type === 'all') {
    computedDate =
      year +
      '-' +
      month +
      '-' +
      date +
      ' ' +
      hours +
      ':' +
      minutes +
      ':' +
      second
  } else if (type === 'year') {
    computedDate = year + '-' + month + '-' + date
  } else {
    computedDate =
      year + '-' + month + '-' + date + ' ' + hours + ':' + minutes
  }
  return computedDate
}
